
/*唤起登录*/
function openLoginK() {
    var login = $("#login");
    layui.use(['layer', 'form'], function () {
        var layer = layui.layer,
            form = layui.form;
        var login_index = layer.open({
            type: 1,
            skin: "loginskin",
            content: login,
            btn: 0,
            close: 0,
            title: false,
            area: ["678px", "390px"],
            end: function () {
                $("#loginBox").hide();
            }
        });
        $("#loginBox").show();
        $(".closeLogin").click(function (e) {
            layer.close(login_index);
        });
    });
}
/*点击切换注册登录*/
$(document).ready(function(){
  $(".zczh").click(function(){
    $("#loginmain").hide();
    $("#regmain").show();
  });
  
  $(".yjyl").click(function(){
    $("#loginmain").show();
    $("#regmain").hide();
  });
});
/*登录注册提交*/
layui.use('form',function(){
  var form = layui.form
  ,jq = layui.jquery;
  /*登录*/
  form.on('submit(homeLogin)', function(data){
    loading = layer.load(2, {
      shade: [0.2,'#000']
    });
    var param = data.field;
    jq.post('/index.php/api/api/homeLogin.html',param,function(data){
      if(data.code == 200){
        layer.close(loading);
        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
          location.reload();
        });
      }else{
        layer.close(loading);
        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
      }
    });
    return false;
  });
  /*注册*/
form.on('submit(homereg)', function(data){
    loading = layer.load(2, {
      shade: [0.2,'#000']
    });
    var param = data.field;
    jq.post('/index.php/api/api/homereg.html',param,function(data){
      if(data.code == 200){
        layer.close(loading);
        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
          $(document).ready(function(){
             $("#loginmain").show();
             $("#regmain").hide();
          });
        });
      }else{
        layer.close(loading);
        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
      }
    });
    return false;
  });
  
 jq('.tuichu').click(function() {
    loading = layer.load(2, {
        shade: [0.2, '#000']
    });
    jq.getJSON('/index.php/api/api/tuichu.html', function(data) {
        if (data.code == 200) {
         layer.close(loading);
        layer.msg(data.msg, {
            icon: 1,
            time: 1000
        }, function() {
             location.reload();
        });
    } else {
        layer.close(loading);
        layer.msg(data.msg, {
            icon: 2,
            anim: 6,
            time: 1000
        });
    }
  });
 });
})
/*退出*/

/*验证码*/
layui.use('form',function(){
  var form = layui.form
  ,jq = layui.jquery;
     jq('#sendRegCode').click(function() {
    var obj = $(this);
    var options = {
        seconds: 60
        , type: 'REG'
    };
     var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"); 
     var mail = $("#usermail").val();
  　　if(mail == ""){ 
  　　　layer.msg('邮箱必填');
  　　　　return false;
  　　}else if(!reg.test(mail)){ 
 　　layer.msg('邮箱格式不对');
 　　　　return false;
 　　}
 　　loading = layer.load(0, {
         shade: [0.2, '#000']
    });
    jq.getJSON('/index.php/api/mail/email.html?mail='+mail, function(data) {
        if (data.code == 200) {
            layer.close(loading);
            layer.msg(data.msg, {
            icon: 1,
            time: 1000
        }, function() {
             countDown(60, obj);
        });
    } 
  });
 });
});
function countDown(seconds, obj) {
    if (seconds > 1) {
        seconds--;
        $(obj).attr('disabled', true).html(seconds + "秒");//禁用按钮
        setTimeout(function () {
            countDown(seconds, obj);
        }, 1000);
    } else {
        $(obj).attr('disabled', false).html("获取验证码");//启用按钮
    }
}
/*导航栏目切换样式*/
var navnow = $(".nav-ul .hover").index();
if (navnow >= 0) {
    $(".border-bottom").css({
        "display": "block",
        "left": $(".nav-ul li").eq(navnow).position().left,
        "width": $(".nav-ul li").eq(navnow).width()
    });
} else {
    $(".border-bottom").hide();
}
$(".nav-ul li").hover(function (e) {
    $(".border-bottom").show();
    $(".nav-ul .hover").removeClass("hover");
    $(this).addClass("hover");
    $(".border-bottom").css({
        "left": $(this).position().left,
        "width": $(this).width()
    });
}, function (e) {
    $(".nav-ul .hover").removeClass("hover");
    if (navnow >= 0) {
        $(".nav-ul li").eq(navnow).addClass("hover");
        $(".border-bottom").css({
            "left": $(".nav-ul li").eq(navnow).position().left,
            "width": $(".nav-ul li").eq(navnow).width()
        });
        return;
    }
    $(".border-bottom").hide();
}); 
/*返回顶部*/
if ($(".backtop").length > 0) {
    backtopS();
    $(window).scroll(function (e) {
        backtopS();
    });

    function backtopS() {
        var scroH = $(this).scrollTop();
        var footerHeight = 0;
        if ($('.friends-link').length > 0) {
            mTop = $('.friends-link')[0].offsetTop;
            footerHeight = footerHeight + $(".friends-link").outerHeight();
        } else {
            mTop = $('footer')[0].offsetTop;
        }
        footerHeight = footerHeight + $("footer").outerHeight() + parseInt($(".content-true").css("margin-top"));
        sTop = $(window).scrollTop();
        result = mTop - sTop - parseInt($(".content-true").css("margin-top"));
        if (scroH > 200) {
            $(".backtop").fadeIn(400);
            if (scroH >= $("body").height() - $(window).height() - footerHeight) {
                $(".backtop").css("bottom", $(window).height() - result);
            } else {
                $(".backtop").css("bottom", "");
            }
        } else {
            $(".backtop").fadeOut(400);
        }
    }
}
$(".backtop").click(function (e) {
    $('body,html').animate({
        scrollTop: 0
    }, 800);
});
layui.use('code', function(){ 
layui.code({
elem: 'pre' 
,encode: true 
,title: '115CMS.COM'
,about: false
//,skin: 'notepad'
});
});